//商品分类全局组件的小仓库
import { defineStore } from "pinia"
import type { ResponseCategoryData } from "../../api/product/attr/type"
import type { CategoryState } from "./types/type"
import {
  reqForstCategory,
  reqSeccendCategory,
  reqThirdCategory,
} from "../../api/product/attr"

const useDefineStore = defineStore("Category", {
  state: (): CategoryState => {
    return {
      c1Arr: [],
      c2Arr: [],
      c3Arr: [],
      c1Id: "",
      c2Id: "",
      c3Id: "",
    }
  },
  actions: {
    async getC1() {
      const result: ResponseCategoryData = await reqForstCategory()
      if (result.code == 200) {
        this.c1Arr = result.data
      }
    },
    async getC2() {
      const result: ResponseCategoryData = await reqSeccendCategory(this.c1Id)
      if (result.code == 200) {
        this.c2Arr = result.data
      }
    },
    async getC3() {
      const result: ResponseCategoryData = await reqThirdCategory(this.c2Id)
      if (result.code == 200) {
        this.c3Arr = result.data
      }
    },
  },
  getters: {},
})

export default useDefineStore
